# 1.导入pymysql
import pymysql

# 2.创建连接对象
conn = pymysql.connect(host='localhost', user='root', password='root', database='advanced', port=3306, charset='utf8')

# 3.创建游标对象
cursor = conn.cursor()
# 4.执行sql语句
# 5.提交或回滚
try:
    sql = "INSRET INTO student(stu_id, stu_no, stu_name) VALUES(8, 'itsrc-016, '许嵩')"
    rows = cursor.execute(sql)
    print('受影响行数：')
except Exception as e:
    print(e)
    conn.rollback()
else:
    conn.commit()

# 6.关闭游标对象
cursor.close()
# 7.关闭连接对象
conn.close()


























